;(function () {
'use strict';
angular.module('services.faultLocation.appAlarmServer')
  .factory('appStrainService', appStrainService);

function appStrainService(Restangular,odOperationDevelop,CoreService,CoreLoading) {
  return {
    queryStrainAppAlarmNum: queryStrainAppAlarmNum,
    getStrainEchartsData: getStrainEchartsData,
    queryDetStrainAppAlarmNum: queryDetStrainAppAlarmNum
  };
  //查询应用告警数
  function queryStrainAppAlarmNum(params) {
    Restangular.all('sas/faultLocation/appAlarms/queryStrainAppAlarmNum').post(params).then(function(res) {
      res.state === '10000' ? getStrainEchartsData(params,res.data.data) : CoreService.dialog('查询错误');
    });
  }
  //表格
  function queryDetStrainAppAlarmNum(params,callback) {
    Restangular.all('sas/faultLocation/appAlarms/queryStrainAppAlarmNum').post(params).then(callback);
  }

  function getStrainEchartsData(param,items) {
    //debugger;
    CoreLoading.setState(false);
    var myEcharts = echarts.init(document.getElementById('doc'));
    var temp = {
      echartsXData: [],
      title: ''
    };
    angular.forEach(items, function(item){
      if(temp.echartsXData.indexOf(item.time)){
        temp.echartsXData.push(item.time);
      }
    });
    if (temp.echartsXData[0] === temp.echartsXData[temp.echartsXData.length - 1]) {
      temp.title = temp.echartsXData[0].replace(/-/g, '') + '应用告警数统计';
    } else {
      temp.title = temp.echartsXData[0].replace(/-/g, '') + '到' + temp.echartsXData[temp.echartsXData.length - 1].replace(/-/g, '') + '应用告警数统计';
    }
    var option = odOperationDevelop.getEchartsData(items,temp.title,'time','isStrainName','alarmNum','bar');
    myEcharts.setOption(option);
  }
 
}
})();